package org.example.forum.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.forum.common.AppResult;
import org.example.forum.model.Board;
import org.example.forum.services.IBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@Api(tags = "板块接口")
@RestController
@RequestMapping("/board")
public class BoardController {
    @Value("${forum.index.board-num:9}")
    private Integer indexBoardNum;

    @Autowired
    IBoardService boardService;

    /**
     * 查询首页板块列表
     * @return
     */
    @ApiOperation("获取首页板块列表")
    @GetMapping("topList")
    public AppResult<List<Board>> toList() {
        log.info("首页板块个数为 :"+ indexBoardNum);

        List<Board> boardList = boardService.selectByNum(indexBoardNum);
        if(null == boardList) {
            boardList = new ArrayList<>();
        }
        return AppResult.success(boardList);
    }
}
